package com.cssnj.portal.service.query;

import com.cssnj.portal.domain.common.UserInfo;
import com.cssnj.portal.utils.PortalUntil;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.predictech.framework.domain.common.JsonRequest;
import io.predictech.framework.domain.common.JsonResponse;
import io.predictech.framework.service.base.BaseService;
import io.predictech.framework.utility.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author Arthur
 * @version 1.0
 * @description 自助办税情况汇总 发票领用（户次）、发票验旧（户次）、发票代开征收税款（笔次）等8项业务的自助办理量 柱状图  CX_ZZBSQKHZ
 * @since 2018-10-16 16:33
 */
@Service
public class Query22Service extends BaseService {

    @Autowired
    @Qualifier("fifthJdbcTemplate")
    private JdbcTemplate fifthJdbcTemplate;

    @Override
    protected JsonResponse invokingService(JsonRequest jsonRequest) {
        return null;
    }


    /**
     * @description 初始化柱图
     * @author Arthur
     * @since 2018-10-16 16:34
     **/
    @SuppressWarnings("SqlDialectInspection")
    public JsonResponse init(JsonRequest jsonRequest) {
        JsonResponse jsonResponse = new JsonResponse();
        UserInfo userInfo = (UserInfo) jsonRequest.getReqData().get("userInfo");
        List<Map<String, Object>> invokeList = fifthJdbcTemplate.queryForList("SELECT T.FPLY_HC,T.FPYJ_HC,T.FPDK_HC,T.FPDKZSSK_BC,T.SKFX_HC,T.FPCB_HC,T.FPRZ_HC,T.QT_HC  FROM CX_ZZBSQKHZ T WHERE T.SWJG_DM = ?", userInfo.getCxjgDm());
        List<Map<String, Object>> colList = fifthJdbcTemplate.queryForList("SELECT COMMENTS FROM (SELECT T.COLUMN_NAME, T.COMMENTS FROM USER_COL_COMMENTS T WHERE TABLE_NAME = 'CX_ZZBSQKHZ') T1 WHERE T1.COLUMN_NAME NOT IN ('SWJG_DM', 'LR_SJ', 'XG_SJ')");
        try {
            jsonResponse.getRepData().put("invoke", StringUtil.getBaseObjectMapper().writeValueAsString(PortalUntil.castMapValue2List(invokeList.get(0))));
            jsonResponse.getRepData().put("xAxis", StringUtil.getBaseObjectMapper().writeValueAsString(colList));
        } catch (JsonProcessingException e) {
           PortalUntil.logger().error("转换 自助办税情况汇总 失败 e : " + e.getMessage());
        }
        return jsonResponse;
    }
}
